﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace DataBaseHelper
{
    /// <summary>
    /// sqlserver连接的方式：数据库、数据库文件
    /// </summary>
    public enum SqlServerConnType
    {
        DBFILE,
        DB
    }
    public  class ConnectionString
    {
        /// <summary>
        /// 连接字符串构造器
        /// </summary>
        private static SqlConnectionStringBuilder connStr = new SqlConnectionStringBuilder();
        /// <summary>
        /// 连接本机名为DBName数据库，使用windows身份验证
        /// </summary>
        /// <param name="DBName">数据库名称</param>
        /// <param name="type">连接类型</param>
        /// <returns>连接字符串</returns>
        public static string GenerateLocalConnStringByWin(string DBName)
        {
                connStr["Server"] = "local";
                connStr.IntegratedSecurity = true;
                connStr.InitialCatalog = DBName;
                connStr["Trusted_Connection"] = true;
                return connStr.ConnectionString;
        }
        /// <summary>
        /// 连接本机名为DBName数据库，使用ID和密码进行身份验证
        /// </summary>
        /// <param name="DBName">数据库名称</param>
        /// <param name="userID">用户名称</param>
        /// <param name="password">用户密码</param>
        /// <returns></returns>
        public static string GenerateLocalConnectionStringByID(string DBName, string userID, string password)
        {
            connStr["Server"] = "local";
            connStr.IntegratedSecurity = false;
            connStr.InitialCatalog = DBName;
            connStr["Trusted_Connection"] = true;
            connStr.UserID = userID;
            connStr.Password = password;
            return connStr.ConnectionString;
        }
    }
//    public class SqlServerDBManager<T>:IDataBase<T>
//    {
//#region 字段
//        /// <summary>
//        /// 连接字符串
//        /// </summary>
//        string connStr;
//#endregion
//        /// <summary>
//        /// 使用windows身份验证连接数据库
//        /// </summary>
//        /// <param name="DBName">数据库名称</param>
//        public SqlServerDBManager(string DBName)
//        {
//            connStr = ConnectionString.GenerateLocalConnStringByWin(DBName);
//        }
//        /// <summary>
//        /// 使用用户名和密码进行数据库连接
//        /// </summary>
//        /// <param name="DBName">数据库名称</param>
//        /// <param name="userID">用户ID</param>
//        /// <param name="password">密码</param>
//        public SqlServerDBManager(string DBName,string userID,string password)
//        {
//            connStr = ConnectionString.GenerateLocalConnectionStringByID(DBName, userID, password);
//        }
//        public static List<T> ExecuteQuery(string queryString)
//        {

//        }
//    }
}
